<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/user_php.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
	$con = @mysql_connect('localhost', 'root', '');
	if (!$con) {
		die("Đã xảy ra lỗi trong quá trình xử lý." . mysql_error());
	}
	
	$db_selected = @mysql_select_db('studial');
	if (!$db_selected) {
		die("Đã xảy ra lỗi trong quá trình xử lý." . mysql_error());
	}

	$sql="SELECT * FROM friends WHERE (user_id='".$_COOKIE['studialuserid']."' AND friend_id='".$_GET['id']."') OR (friend_id='".$_COOKIE['studialuserid']."' AND user_id='".$_GET['id']."');";
	$result = mysql_query($sql);
	$rows = mysql_num_rows($result);
	$i = 2; //themselves
	if($rows)
	{
		//friend
		$i = 1;
	}
	else if ($_COOKIE['studialuserid'] != $_GET['id'])
	{
		//not friend
		$i = 0;
	}
	
	//Get homeboard info
	$sql="SELECT * FROM `users` WHERE `id`='".$_GET['id']."'";
	$result=mysql_query($sql);
	$row=mysql_fetch_array($result);
	$fullnametarget=$row["lastname"]." ".$row["firstname"];
	
	//Get homeboard info
	$sql="SELECT * FROM `users` WHERE `id`='".$_COOKIE['studialuserid']."'";
	$result=mysql_query($sql);
	$row=mysql_fetch_array($result);
	$fullnameuser=$row["lastname"]." ".$row["firstname"];
?>
<title><?php echo $fullnametarget; ?></title>
<link rel="stylesheet" type="text/css" href="../css/global.css" />
<link rel="stylesheet" type="text/css" href="../css/loggedpages.css" />
<!-- InstanceBeginEditable name="head" -->
<link rel="stylesheet" type="text/css" href="../css/boards.css" />
<!-- InstanceEndEditable -->
</head>

<body>  
    <div class="header">
        <div class="innercontent">
            <img alt="Studial" class="logo" src="../images/logo.jpg" />   
            <form id="searchform" method="post" action="">
                <div id="searchblock">
                    <input id="searchfield" name="searchfield" type="text" placeholder="Tìm kiếm" />
                    <button id="searchbutton" type="submit" name="search" value="1" title="Tìm kiếm" onclick="window.location = '../unlogged/index.php'"><img id="searchicon" src="../images/searchicon.png" /></button>
                </div>           
            </form>
            <div id="rightheader">
                <a class="headerbutton" id="logout" href="../unlogged/logout.php"><span id="borderleft"></span>Đăng xuất</a>
                <a class="headerbutton" id="toboard" href="<?php echo "../users/addfriend.php?id=".$_COOKIE["studialuserid"]; ?>"><?php echo $fullnameuser; ?></a>
            </div>
        </div>
    </div>
    <div class="innercontent">
        <div id="leftcolumn">
            <img alt="Avatar" id="largeavatar" src="<?php echo $path = "../images/male_avatar.png"; ?>" />
        	<div id="sidenavcontainer">	
                <ul id="sidenav">
            		<li><a class="navlink" href="homeboard.php?id=<?php echo $_GET['id']; ?>"><span id="boardnav">Bảng</span></a></li>
                    <li><a class="navlink" href="infoview.php?id=<?php echo $_GET['id']; ?>"><span id="infonav">Thông tin</span></a></li>
                    <li><a class="navlink" href="friendlist.php?id=<?php echo $_GET['id']; ?>"><span id="friendnav">Bạn bè</span></a></li>
                    <li><a class="navlink" href="phovidallview.php?id=<?php echo $_GET['id']; ?>"><span id="phovidnav">Phim ảnh</span></a></li>
                    <li><a class="navlink" href="courselist.php?id=<?php echo $_GET['id']; ?>"><span id="coursenav">Khóa học</span></a></li>
            	</ul>
            </div>
        </div>
        <div id="contentcolumn">
        	<div id="contentcolheader">
            	<h2><?php echo $fullnametarget; ?></h2>
                <?php 
					if ($i == 0) { 
						echo "<a id=\"addfriend\" href=\"../users/addfriend.php?id=".$_GET["id"]."\"><button class=\"greenbutton\">Kết bạn</button></a>";
					}
				 	else if ($i == 1) {
						echo "<a id=\"removefriend\" href=\"../users/removefriend.php?id=".$_GET["id"]."\"><button class=\"greenbutton\">Chia tay</button></a>"; 
					}
				?>  
            </div>
		<!-- InstanceBeginEditable name="maincontent" -->
			<?php
				$password = $_COOKIE['studialuserpwd'];
								
				$selectTopics = "SELECT * FROM `topics` LEFT JOIN `users` ON `topics`.`user_id` = `users`.`id` WHERE `home_id` = '".$_GET['id']."' AND `type` = '1'";
				$resultTopics = mysql_query($selectTopics);
				$numTopicsResult = mysql_num_rows($resultTopics);	
			?>
            <form id="topicform" method="post" action="topic.php">
                <input name="homeid" type="hidden" value="<?php echo $_GET['id']; ?>" />
                <div class="topicoutline">
                    <textarea id="topicinput" name="topic" placeholder="Viết chủ đề" title="Viết chủ đề"></textarea>
                    <input type="text" id="topiclink" name="link" placeholder="Điền liên kết" title="Điền liên kết" />
                </div>
                <button class="greenbutton" type="submit" id="topicsubmit" name="submit" value="1" title="Đăng chủ đề">Đăng</button>
            </form>          
			<?php
				for($i=1; $i<=$numTopicsResult; $i++)
				{
					$rowTopics = mysql_fetch_array($resultTopics);
					
					$selectComments = "SELECT * FROM `comments` LEFT JOIN `users` ON `comments`.`user_id` = `users`.`id`  WHERE `topic_id` = '".$rowTopics['id']."'";
					$resultComments = mysql_query($selectComments);
					$numCommentsResult = mysql_num_rows($resultComments);
					
					$photoquery = @mysql_query("SELECT `path` FROM `photos` INNER JOIN `topics` ON `photos`.`user_id` = `topcics`.`user_id` WHERE `topic_id` = '".$rowTopics['id']."'");
										
					echo '<div class="postcontainer">';
            		echo '<div class="leftavatar">';
                	echo '<img alt="Ava" src="../images/male_avatar.png" />';
               		echo '</div>';
                	echo '<div class="topiccol">';
					echo '<div class="topicblock">';
					echo '	<div class="topicusername">';
					echo 		htmlspecialchars($rowTopics['lastname'])." ".htmlspecialchars($rowTopics['firstname']); 
					echo '	</div>';
					echo '	<div class="topiccontent">';
					echo 		htmlspecialchars($rowTopics['content']);  
					echo '	</div>';
					echo '	<div class="topiclink">';
					echo '		<a href="'.htmlspecialchars($rowTopics['path']).'">'.htmlspecialchars($rowTopics['path']).'</a>';
					echo '	</div>';
					echo '	<div class="topicinfo">';
					echo '		<span class="topiclike" id="topicid">';
					echo '			<a href="../liketopic.php?homeid="'.$_GET['id'].'>Thích</a>';
					echo ' 		</span>';
					echo 		' - '.htmlspecialchars($rowTopics['datecreated']); 
					echo '	</div>';
					echo '</div>';
					echo '<div class="topicrefblock">';
					echo '	<div class="blueblock"><img alt="Like" src="../images/likeicon.png" />';
					echo 		htmlspecialchars($rowTopics['numliked']).' người thích và '; 
					echo 		htmlspecialchars($rowTopics['numcommented']).' bình luận'; 
					echo '	</div>';
					echo '	<div class="commentcontainer">';
					for($j=1; $j<=$numCommentsResult; $j++)
					{
						$rowComments = mysql_fetch_array($resultComments);
						
						echo '		<div class="blueblock">';
						echo '			<span class="commentusername">';
						echo 				htmlspecialchars($rowComment['lastname'])." ".htmlspecialchars($rowComment['firstname']); 
						echo '			</span>';
						echo '			<span class="commentcontent">';
						echo 				htmlspecialchars($rowComments['content']);
						echo '			</span>';
						echo '			<span class="commentlink">';
						echo '				<a href="'.htmlspecialchars($rowComments['path']).'"></a>';
						echo '			</span>';
						echo '			<div class="commentinfo">';
						echo '				<span class="commentlike" id="commentid">';
						echo '					<a href="../likecomment.php?commentid="'.$rowComments['id'].'>Thích</a>';
						echo '				</span>';
						echo 				' - '.htmlspecialchars($rowComments['datecommented']); 
						echo '			</div>';
						echo '		</div>';
					}
					echo '	</div>';
					echo '	<div class="blueblock">';
					echo '		<form class="commentform" name="commentform" method="post" action="comment.php">';
					echo '			<input name="homeid" type="hidden" value="'.$_GET['id'].'" />';
					echo '			<input name="topicid" type="hidden" value="'.$rowTopics['id'].'" />';
					echo '			<div class="commentoutline">';
					echo '				 <textarea name="comment" placeholder="Viết bình luận" title="Viết bình luận"></textarea>';
					echo '				<input type="text" name="link" placeholder="Điền liên kết" title="Điền liên kết" />';
					echo '			</div>';
					echo '			<button class="greenbutton" type="submit" name="submit" value="1" title="Đăng bình luận">Đăng</button>';
					echo '		</form>';
					echo '	</div>';
					echo '</div>';
					echo '</div>';
					echo '</div>';
				}
			?>
		<!-- InstanceEndEditable -->
    	</div>
    </div>
    <div class="footer">
    	<div id="leftfooter">Studial @ 2012 - Nhóm 01</div>
        <div id="rightfooter">
			<a href="" title="Đăng ký thêm tên trường vào hệ thống">Đăng ký trường</a>
            -
            <a href="" title="Đăng ký thêm tên ngành học vào hệ thống">Đăng ký ngành</a>
        </div>
    </div>       
</body>
<!-- InstanceEnd --></html>
